#include<iostream>
#include<cstring>
using namespace std;
#define x first
#define y second
typedef pair<int, int> PII;
const int N = 1010;
int arr[N][N];
PII preV[N][N];
bool st[N][N];
int n;
PII q[N * N];
void bfs(int sx, int sy)
{
	int hh = 0, tt = 0;
	q[0] = { sx,sy };
	st[sx][sy] = 1;
	
	int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };

	while (hh <= tt) {	
		PII t = q[hh++];
		for (int i = 0; i < 4; i++) {
			int a = t.x + dx[i];
			int b = t.y + dy[i];
			if (a < 0 || a >= n || b < 0 || b >= n)continue;
			if (st[a][b])continue;
			if (arr[a][b])continue;
			preV[a][b] = { t.x,t.y };
			//cout << a << " " << b << endl;
			q[++tt] = { a,b };
			st[a][b] = 1;
			if (a == 0 && b == 0) {
				return;
			}
		}
	}
}
int main()
{
	cin >> n;
	memset(preV, -1, sizeof(preV));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> arr[i][j];
		}
	}
	bfs(n - 1, n - 1);
	int u = 0;
	int v = 0;
	while (u >= 0 && v >= 0) {
		cout << u << " " << v << endl;
		PII temp = preV[u][v];
		u = temp.x, v = temp.y;
	}
	return 0;
}